package pers.wwz.study.wechatserver.utils.subscribemsg;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import pers.wwz.study.wechatserver.dto.MsgDTO;
import pers.wwz.study.wechatserver.feign.request.SendSubscribeMgRequest;
import pers.wwz.study.wechatserver.utils.DateUtils;

import java.util.Date;
import java.util.HashMap;

@Slf4j
@Component
public class SubscribeMsgUtils {


    /**
     * 构建客户报备请求
     * @param msgDTO
     */
    public static SendSubscribeMgRequest buildSubscribeCustomerRequest(MsgDTO msgDTO) {
        SendSubscribeMgRequest sendSubscribeMgRequest = new SendSubscribeMgRequest();
        sendSubscribeMgRequest.setTouser(msgDTO.getOpenid());
        // 模板id
        sendSubscribeMgRequest.setTemplate_id("4z5sVBmqu0f-98Z9UMzXlk4gkrziH_bbd7YvWY1pNDE");
        // 微信小程序页面地址
        sendSubscribeMgRequest.setPage("pages/index/index");
        // 语言
        sendSubscribeMgRequest.setLang("zh_CN");
        // 跳转小程序类型：developer为开发版；trial为体验版；formal为正式版；默认为正式版
        sendSubscribeMgRequest.setMiniprogram_state("developer");
        HashMap<String, Object> dataMap = new HashMap<>();
        HashMap<String, Object> date1 = new HashMap<>();
        date1.put("value", DateUtils.dateToString(new Date(),"yyyy-MM-dd HH:mm:ss"));

        HashMap<String, Object> date2 = new HashMap<>();
        date2.put("value", DateUtils.dateToString(new Date(),"yyyy-MM-dd HH:mm:ss"));

        HashMap<String, Object> thing3 = new HashMap<>();
        thing3.put("value", msgDTO.getName()+"电话:"+ msgDTO.getPhone());
        dataMap.put("date1", date1);
        dataMap.put("date2",date2);
        dataMap.put("thing3",thing3);
        sendSubscribeMgRequest.setData(dataMap);

        return sendSubscribeMgRequest;
    }
}
